package org.finir.fakturisanje.business.eao;

import org.finir.fakturisanje.business.core.HibernateGenerickiEAOImpl;
import org.finir.fakturisanje.persistence.Preduzece;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.criterion.Restrictions;
import org.springframework.transaction.annotation.Transactional;

@Transactional
public class PreduzeceEAOImpl extends HibernateGenerickiEAOImpl implements
		PreduzeceEAO {

	/**
	 * 
	 */
	private static final long serialVersionUID = -4979140707012623391L;

	public Preduzece preduzeceLogin(Preduzece preduzece) {

		Session session = getSessionFactory().getCurrentSession();

		Criteria criteria = session.createCriteria(Preduzece.class);

		criteria.add(Restrictions.eq("username", preduzece.getUsername()));
		criteria.add(Restrictions.eq("password", preduzece.getPassword()));

		Preduzece pred = (Preduzece) criteria.uniqueResult();
		if (pred == null) {
			return null;
		}

		else {
			return pred;
		}
	}

}
